import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsNotEmpty, IsOptional, IsUUID, ValidateIf } from 'class-validator';
import { ArticleTagEntity } from '../entities/article.tag.entity';

export class ArticleDto {
  @ApiProperty({ required: true, description: '标题' })
  @IsNotEmpty({ message: '内容不能为空' })
  readonly title: string;

  @ApiProperty({ required: true, description: '内容' })
  @IsNotEmpty({ message: '内容不能为空' })
  readonly content: string;

  @ApiPropertyOptional({ required: false, description: '标签' })
  @IsOptional()
  readonly tag?: ArticleTagEntity[];

  @ApiPropertyOptional({ required: false, description: '图片' })
  @IsOptional()
  readonly picture?: string;

  @ValidateIf((o) => Array.isArray(o.tags))
  @IsUUID('4', { each: true, message: 'tagid不对' })
  tags: string[];
}
